package edu.dlnu.newbootdemo.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import edu.dlnu.newbootdemo.dao.StudentMapper;
import edu.dlnu.newbootdemo.pojo.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author :JinFeng
 * @description :
 * @create :2023/6/27
 */

@Service
public class StudentServiceImpl implements IStudentService {
    @Autowired
    private StudentMapper mapper;
    @Override
    public List<Student> getStudents(int currPage) {
        // 实现分页：分页配置类
        PageHelper.startPage(currPage, 3);
        List<Student> list = mapper.queryAll();
        // 分页器
        PageInfo<Student> info = new PageInfo<>(list);
        return info.getList();
    }

    @Override
    public Student queryStudentByNo(int sno) {
        return mapper.queryByNo(sno);
    }

    @Override
    public boolean addStudent(Student s) {
        return mapper.add(s) > 0;
    }

    @Override
    public boolean updateStudent(Student s) {
        return mapper.update(s) > 0;
    }

    @Override
    public boolean delStudent(int sno) {
        return mapper.delete(sno) > 0;
    }
}
